import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { ItemData } from "../../resource/info/ItemData";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { DragEvent } from "../../../../com/mui/events/DragEvent";
import { GTextFormat } from "../../../common/GTextFormat";
import { TilePanel } from "../equipment/TilePanel";
import { SellItemRenderer } from "./SellItemRenderer";
import { ECategory } from "../../../../Message/Public/ECategory";
import { ColorConfig } from "../../resource/ColorConfig";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { DataEvent } from "../../events/DataEvent";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
type int = number;
//class SellGoodsTips
    
    export  class SellGoodsTips extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            if (SellGoodsTips._instance != null) 
            {
                throw new Error("SellGoodsTips");
            }
            setSize(340, 280);
            title = Language.getString(30149);
            titleHeight = 30;
            Dispatcher.addEventListener(EventName.MarketSellGoodsItemSelect, this.onSellGoodsItemSelectHandler);
            return;
        }

        public SellGoodsTips.get itemUid(): string
        {
            if (this._baseItem.itemData != null) 
            {
                return this._baseItem.itemData.uid;
            }
            return "";
        }

        public SellGoodsTips.get amount(): int
        {
            return this._numStepper.value;
        }

        public SellGoodsTips.get itemData(): ItemData
        {
            if (this._baseItem.itemData != null) 
            {
                return this._baseItem.itemData;
            }
            return null;
        }

        public SellGoodsTips.get itemCategory(): int
        {
            if (this._baseItem.itemData != null) 
            {
                return this._baseItem.itemData.category;
            }
            return 0;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(17, 43, 306, 230, this);
            ObjCreate.createTextField(Language.getString(31130), 100, 50, 200, 20, this);
            ObjCreate.createBg(30, 75, 280, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBitmap(ImagesConst.PackItemBg, 155, 90, this);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(33, 33);
            this._baseItem.move(158, 93);
            addChild(this._baseItem);
            this._baseItem.addEventListener(DragEvent.Event_Move_In, this.onItemMoveInHandler);
            this._baseItem.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClickHandler);
            ObjCreate.createTextField(Language.getString(31131), 115, 142, 80, 20, this);
            this._numStepper = ObjCreate.createGNumericStepper(195, 140, 50, 22, this);
            this._numStepper.addEventListener(flash.events.Event.CHANGE, this.onNumStepperChangeHandler);
            ObjCreate.createBg(30, 170, 280, 2, this, ImagesConst.SplitLine);
            this._textfield = ObjCreate.createTextField("", 20, 180, 300, 80, this, new GTextFormat("", 12, 16777215, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._textfield.wordWrap = true;
            this._textfield.multiline = true;
            this._sureBtn = ObjCreate.createGButton(Language.getString(30151), 100, 225, 50, 25, this);
            this._sureBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSureBtnClickHandler);
            this._cancelBtn = ObjCreate.createGButton(Language.getString(30152), 190, 226, 50, 25, this);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            ObjCreate.createBg(345, 30, 180, 250, this);
            this._itemListPanel = new TilePanel();
            this._itemListPanel.horizontalGap = 5;
            this._itemListPanel.verticalGap = 5;
            this._itemListPanel.columnWidth = 38;
            this._itemListPanel.rowHeight = 38;
            this._itemListPanel.columnCount = 4;
            this._itemListPanel.setSize(175, 215);
            this._itemListPanel.setStyle("cellRenderer", SellItemRenderer);
            this._itemListPanel.move(350, 35);
            addChild(this._itemListPanel);
            return;
        }

        /* internal  */onItemMoveInHandler(arg1: DragEvent): void
        {
            var loc1=arg1.dragItem as BaseItem;
            var loc2=loc1.itemData;
            if (loc2.category == ECategory._ECategoryAmulet && loc2.isHasIdentify()) 
            {
                return;
            }
            this._baseItem.itemData = loc2;
            if (this._baseItem.itemData.itemAmount < this._amount) 
            {
                this._numStepper.maximum = this._baseItem.itemData.itemAmount;
            }
            else 
            {
                this._numStepper.maximum = this._amount;
            }
            this.onNumStepperChangeHandler();
            return;
        }

        /* internal  */onItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._textfield.htmlText = "";
            this._baseItem.itemData = null;
            this._numStepper.value = 1;
            return;
        }

        /* internal  */onNumStepperChangeHandler(arg1: Object /* flash.events.Event */=null): void
        {
            if (this._baseItem.itemData == null) 
            {
                return;
            }
            var loc1=ColorConfig.instance.getItemColor(this._color).color;
            var loc2=this._numStepper.value;
            var loc3="";
            if (this._unit != EPrictUnit._EPriceUnitCoin) 
            {
                if (this._unit == EPrictUnit._EPriceUnitGold) 
                {
                    loc3 = this._unitPrice * loc2 + " " + Language.getString(31037);
                }
            }
            else 
            {
                loc3 = this._unitPrice * loc2 + " " + Language.getString(31036);
            }
            this._textfield.htmlText = Language.getStringByParam(31132, loc2, loc1, this._baseItem.itemData.itemInfo.item.name, loc3);
            return;
        }

        /* internal  */onSureBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._eventFunction != null) 
            {
                this._eventFunction();
            }
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        public updateInfo(arg1: int, arg2: int, arg3: int, arg4: Array<any>, arg5: int, arg6: Function): void
        {
            this._color = arg1;
            this._unitPrice = arg2;
            this._unit = arg3;
            this._eventFunction = arg6;
            this._amount = arg5;
            this._itemListPanel.selectedIndex = -1;
            this._itemListPanel.dataProvider = new DataProvider(arg4);
            this._baseItem.itemData = null;
            this._numStepper.value = 1;
            this._textfield.text = "";
            return;
        }

        /* internal  */onSellGoodsItemSelectHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as ItemData;
            this._baseItem.itemData = loc1;
            if (loc1.itemAmount < this._amount) 
            {
                this._numStepper.maximum = loc1.itemAmount;
            }
            else 
            {
                this._numStepper.maximum = this._amount;
            }
            this.onNumStepperChangeHandler();
            return;
        }

        public static get instance(): SellGoodsTips
        {
            if (SellGoodsTips._instance == null) 
            {
                SellGoodsTips._instance = new SellGoodsTips();
            }
            return SellGoodsTips._instance;
        }

        /* internal */ /* var */_textfield: Object /* flash.text.TextField */;

        /* internal */ /* var */_sureBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_itemListPanel: TilePanel;

        /* internal */ /* var */_numStepper: GNumericStepper;

        /* internal */ /* var */_eventFunction: Function=null;

        /* internal */ /* var */_amount: int;

        /* internal */ /* var */_color: int;

        /* internal */ /* var */_unitPrice: int;

        /* internal */ /* var */_unit: int;

        /* internal */ static /* var */_instance: SellGoodsTips;
    }
